package com.zhima.controller.feign;

import cn.hutool.core.bean.BeanUtil;
import com.zhima.dto.FeignSimpleContestInfo;
import com.zhima.service.OjContestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhima
 * @since 2024-01-18
 */
@RestController
@RequestMapping("/contest/feign")
public class OjContestFeignController {
    @Autowired
    private OjContestService ojContestService;

    /**
     * 记录用户{contestId}的比赛中{questionIndex}索引的题目提交过了
     *
     * @param contestId
     * @param questionIndex
     * @param userId
     * @return
     */
    @PostMapping("/{contestId}/{questionIndex}/{userId}")
    public boolean recordUserSubmit(@PathVariable("contestId") Long contestId, @PathVariable("questionIndex") Integer questionIndex, @PathVariable("userId") Long userId) {
        return ojContestService.recordUserSubmit(contestId, questionIndex, userId);
    }

    /**
     * 根据{contestId}获取比赛简略信息
     *
     * @param contestId
     * @return
     */
    @GetMapping("/{contestId}")
    public FeignSimpleContestInfo getSimpleContestInfo(@PathVariable("contestId") Long contestId) {
        // 这里直接使用BeanUtil复制到FeignSimpleContestInfo
        return BeanUtil.copyProperties(ojContestService.getById(contestId), FeignSimpleContestInfo.class);
    }

    @GetMapping("/magnification/{contestId}/{questionIndex}")
    public Integer getMagnification(@PathVariable("contestId") Long contestId, @PathVariable("questionIndex") Integer questionIndex) {
        return ojContestService.getMagnification(contestId, questionIndex);
    }
}
